package com.FengChaoSystem.service.NewService;

import com.FengChaoSystem.dao.NewDao;
import com.FengChaoSystem.pojo.New;
import com.FengChaoSystem.pojo.User;
import com.FengChaoSystem.service.NewImpl;
import com.FengChaoSystem.untils.SqlSessionFactoryUtils;
import com.Mybatis.session.SqlSession;
import com.Mybatis.session.SqlSessionFactory;

import java.util.List;

public class NewService implements NewImpl {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();



    @Override
    public List<New> selectAllNew(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        NewDao mapper = sqlSession.getMapper(NewDao.class);
        List<New> news = mapper.selectAllNew(user);
        sqlSession.close();
        return news;
    }

    @Override
    public void addNeedGetNew(New target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        NewDao mapper = sqlSession.getMapper(NewDao.class);
        mapper.addNeedGetNew(target);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void addPushNew(New target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        NewDao mapper = sqlSession.getMapper(NewDao.class);
        mapper.addNeedGetNew(target);
        sqlSession.commit();
        sqlSession.close();

    }
}
